package com.hospital.pony.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hospital.R;
import com.hospital.pony.db.MemberUserUtils;
import com.hospital.pony.model.UserModel;
import com.squareup.picasso.Picasso;

//本例子来自：http://myapptg.com 更多资源请访问该网站
public class LiaoTianAdpter extends BaseAdapter {
	private List<LiaoTianBean> liaoTianBeans;
	private Context context;
	private LayoutInflater layoutInflater;
	private int tid;
	

	public LiaoTianAdpter(List<LiaoTianBean> liaoTianBeans, Context context) {
		this.liaoTianBeans = liaoTianBeans;
		this.context = context;
		layoutInflater = LayoutInflater.from(context);

	}

	@Override
	public int getCount() {
		return liaoTianBeans.size();
	}

	@Override
	public Object getItem(int arg0) {
		return liaoTianBeans.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View viewMessage, ViewGroup arg2) {
		Holder holder = new Holder();
		if (liaoTianBeans.get(arg0).getState() == LiaoTianBean.JIESHOU) {
			viewMessage = layoutInflater.inflate(R.layout.chatting_item_msg_text_left, null);
		} else {
			viewMessage = layoutInflater.inflate(R.layout.chatting_item_msg_text_right, null);
		}
		

		holder.contenTextView = (TextView) viewMessage.findViewById(R.id.tv_chatcontent);
		holder.contenTextView.setText(liaoTianBeans.get(arg0).getMessage());
		
		
		holder.imageView = (ImageView) viewMessage.findViewById(R.id.iv_userheaduser);

		
		if (liaoTianBeans.get(arg0).getState() == LiaoTianBean.JIESHOU) {
			holder.imageView.setImageResource(R.drawable.icon_jiqiren);
//			viewMessage = layoutInflater.inflate(R.layout.chatting_item_msg_text_left, null);
		} else {
			UserModel userModel = (UserModel) MemberUserUtils.getBean(context, "user_messgae");
			if (userModel.getUtype().equals("1")) {
				Picasso.with(context).load("http://img5.duitang.com/uploads/item/201602/29/20160229194418_dtkcX.thumb.224_0.jpeg")
						.placeholder(R.drawable.icon_ponydef).into(holder.imageView );
			} else {
				Picasso.with(context).load("http://www.qqzhi.com/uploadpic/2014-09-21/140925601.jpg").placeholder(R.drawable.icon_ponydef)
						.into(holder.imageView );
			}

			
//			UserModel userModel = (UserModel) MemberUserUtils.getBean(context, "user_messgae");
//			if (!TextUtils.isEmpty(userModel.getUimage())) {
//				Picasso.with(context).load(Consts.URL_IMAGE_LOCAL + userModel.getUimage()).placeholder(R.drawable.default_drawable_show_pictrue)
//						.into(holder.imageView);
//			}
		}
		
		
	
	

		return viewMessage;
	}

	static class Holder {
		public TextView contenTextView;
		public ImageView imageView;
	}

}
